package cn.edu.scnu.swagger.controller;

import cn.edu.scnu.exception.NoAuthority;
import cn.edu.scnu.exception.NoLoginException;
import cn.edu.scnu.vo.ResultCode;
import cn.edu.scnu.vo.SysResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalController {

    @ExceptionHandler(NoLoginException.class)
    public SysResult checkLogin(Exception e) {
        return SysResult.build(ResultCode.UNAUTHORIZED, e.getMessage(), null);
    }

    @ExceptionHandler(NoAuthority.class)
    public SysResult checkAuthority(Exception e) {
        return SysResult.build(ResultCode.FORBIDDEN, e.getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    public SysResult myException(Exception e) {
        e.printStackTrace();
        return SysResult.build(ResultCode.FAIL, e.getMessage(), null);
    }
}
